package com.test;

import com.wdciti.sccp.iot.springvertx.annotation.VerticleBean;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.datagram.DatagramSocket;
import io.vertx.core.datagram.DatagramSocketOptions;
import io.vertx.core.net.SocketAddress;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@VerticleBean(isWorker = false)
public class PibTestVerticle extends AbstractVerticle {

    @Override
    public void start() {
        DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
        socket
                .handler(packet -> {
                    SocketAddress address = packet.sender();
                    log.info("address--> host:{},port:{},path:{}",address.host(),address.port(),address.path());
                    Buffer buffer = packet.data();
                    log.info(buffer.toString());
                        // Do something with the packet
                })
                .listen(5688, "0.0.0.0")
                .onComplete(asyncResult -> System.out.println("Send succeeded? " + asyncResult.succeeded()));
        ;
    }

    @Override
    public void stop() throws Exception {
        super.stop();
    }

}
